﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.ServiceModel.Syndication;
using System.Xml;

namespace Sisocana.Core.Models
{
    public class NoticiaModel : FuenteModel
    {
        public string logoURL { get; set; }

        [Required]
        [DisplayName("RSS Feed Url")]
        public string feedurl { get; set; }

        public void obtenerInformacion()
        {
            try
            {
                using (XmlReader reader = XmlReader.Create(feedurl))
                {
                    SyndicationFeed rssData = SyndicationFeed.Load(reader);
                    this.descripcion = rssData.Description.Text;
                    this.pagWeb = rssData.Links[0].Uri.OriginalString;
                    if (rssData.ImageUrl !=null)
                    {

                            logoURL = rssData.ImageUrl.OriginalString;
                            //WebClient client = new System.Net.WebClient();
                            //this.logo = client.DownloadData(logoURL);
                            ////System.IO.File.WriteAllBytes(@"C:\Temp\test.gif", logo);

                            //this.logoNomb = logoURL.Substring(logoURL.LastIndexOf("/") + 1, (logoURL.Length - logoURL.LastIndexOf("/") - 1));
                            //this.logoExt = logoNomb.Substring(logoNomb.LastIndexOf(".") + 1, (logoNomb.Length - logoNomb.LastIndexOf(".") - 1));
                     }
                }
            }
            catch (Exception e)
            {
            }
        }
    }
}
